<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryForm"
      size="mini"
      :inline="true"
      v-show="showSearch"
      label-width="68px"
    >
      <el-form-item label-width="70px" label="发砼时间">
        <QuickFilterDate :disableArr="[5,6,7]" v-model="queryDateArr" />
      </el-form-item>
      <el-form-item label="退剩类型" prop="returnType">
        <el-select v-model="queryParams.returnType" placeholder="请选择">
          <el-option label="退砼" :value="0"></el-option>
          <el-option label="剩砼" :value="1"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item
        label-width="110px"
        label="退剩砼处置结论"
        prop="handleResult"
      >
        <el-select v-model="queryParams.handleResult" placeholder="请选择">
          <el-option label="待处理" :value="1"></el-option>
          <el-option label="需作废" :value="2"></el-option>
          <el-option label="同级转售" :value="3"></el-option>
          <el-option label="降级转售" :value="4"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label-width="70px" label="车辆编号" prop="carNumber">
        <el-input
          v-model.trim="queryParams.carNumber"
          placeholder="请输入车辆编号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="司机姓名" prop="carOwner">
        <el-input
          v-model.trim="queryParams.carOwner"
          placeholder="请输入司机姓名"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
          >搜索</el-button
        >
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
          >重置</el-button
        >
      </el-form-item>
    </el-form>

    <el-table
      v-loading="loading"
      max-height="390"
      :data="teamList"
      @selection-change="handleSelectionChange"
    >
      <el-table-column type="selection" width="55" align="center" />

      <el-table-column width="60" label="砼单ID" align="center" prop="concreteId" />
      <!-- <el-table-column label="订单编号" align="center" prop="teamName" />-->
      <el-table-column width="100" label="退剩类型" align="center">
        <template slot-scope="scope">
          <span v-if="scope.row.returnType == 0">退砼</span>
          <span v-if="scope.row.returnType == 1">剩砼</span>
        </template>
      </el-table-column>
      <el-table-column width="100" label="退剩方量" align="center" prop="returnVolume" />
      <el-table-column width="100" label="砼车编号" align="center" prop="carNumber" />
      <el-table-column width="120" label="砼车司机" align="center" prop="carOwner" />
      <!-- <el-table-column label="发砼时间" align="center" prop="teamName" />
      <el-table-column label="主标号" align="center" prop="teamName" />
      <el-table-column label="主标号一级品类" align="center" prop="teamName" />
      <el-table-column label="附加产品标号" align="center" prop="teamName" /> -->
      <el-table-column label="工程名称" align="center" prop="engineeringName" />
      <el-table-column label="处置结论" align="center" prop="handleResult">
        <template slot-scope="scope">
          <span v-if="scope.row.handleResult == 1">待处理</span>
          <span v-if="scope.row.handleResult == 2">需作废</span>
          <span v-if="scope.row.handleResult == 3">同级转售</span>
          <span v-if="scope.row.handleResult == 4">降级转售</span>
        </template>
      </el-table-column>
      <el-table-column
        fixed="right"
        width="200"
        label="操作"
        align="center"
        class-name="small-padding fixed-width"
      >
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            v-if="scope.row.handleResult == 2"
            @click="handleZf(scope.row)"
            v-hasPermi="['system:team:edit']"
            >作废</el-button
          >
          <el-button
            size="mini"
            type="text"
            @click="handleSt(scope.row)"
            v-if="!scope.row.handleResult"
            v-hasPermi="['system:team:edit']"
            >剩砼</el-button
          >
          <el-button
            size="mini"
            type="text"
            v-if="!scope.row.handleResult"
            @click="handleTt(scope.row)"
            v-hasPermi="['system:team:edit']"
            >退砼</el-button
          >
          <el-button
            size="mini"
            type="text"
            v-if="scope.row.handleResult == 1"
            @click="handleCl(scope.row)"
            v-hasPermi="['system:team:remove']"
            >处理</el-button
          >
          <el-button
            size="mini"
            type="text"
            @click="handleJjfw(scope.row)"
            v-hasPermi="['system:team:remove']"
            >降级范围</el-button
          >
          <el-button
            size="mini"
            type="text"
            @click="handleZs(scope.row)"
            v-hasPermi="['system:team:remove']"
            >转售</el-button
          >
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 处理 -->
    <el-dialog
      title="处理退剩砼"
      :visible.sync="clOpen"
      width="500px"
      append-to-body
    >
      <el-form
        label-position="left"
        ref="cl-form"
        :model="form"
        :rules="rules"
        label-width="80px"
      >
        <el-form-item
          :rules="[{ required: true, message: '请选择', trigger: 'blur' }]"
          label="处置结论"
          label-width="100px"
          prop="handleResult"
        >
          <el-radio-group v-model="form.handleResult">
            <el-radio :label="2">需作废</el-radio>
            <el-radio :label="3">同级转售</el-radio>
            <el-radio :label="4">降级转售</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item
          v-if="form.handleResult == 4"
          :rules="[{ required: true, message: '请选择', trigger: 'blur' }]"
          label="降级标号"
          label-width="100px"
          prop="demoteDesignIds"
        >
          <div style="display: flex; gap: 20px; align-items: center">
            <span v-if="form.demoteDesignIds">{{
              form.demoteDesignNames
            }}</span>
            <el-button type="text" @click="selectMainVisible = true">{{
              form.demoteDesignIds ? "请重新选择" : "请选择"
            }}</el-button>
          </div>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="subCl">确 定</el-button>
        <el-button @click="clOpen = false">取 消</el-button>
      </div>
    </el-dialog>

    <!-- 标记剩砼 -->
    <el-dialog
      title="标记剩砼"
      :visible.sync="stOpen"
      width="500px"
      append-to-body
    >
      <el-form
        label-position="left"
        ref="st-form"
        :model="form"
        :rules="rules"
        label-width="80px"
      >
        <el-form-item
          :rules="[{ required: true, message: '请填写', trigger: 'blur' }]"
          label="剩砼方量"
          label-width="100px"
          prop="returnVolume"
        >
          <el-input
            v-model="form.returnVolume"
            type="number"
            placeholder="请填写"
          />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="subSt">确 定</el-button>
        <el-button @click="stOpen = false">取 消</el-button>
      </div>
    </el-dialog>

    <!-- 标记退砼 -->
    <el-dialog
      title="标记退砼"
      :visible.sync="ttOpen"
      width="500px"
      append-to-body
    >
      <el-form
        label-position="left"
        ref="tt-form"
        :model="form"
        :rules="rules"
        label-width="80px"
      >
        <el-form-item
          :rules="[{ required: true, message: '请填写', trigger: 'blur' }]"
          label="退砼方量"
          label-width="100px"
          prop="returnVolume"
        >
          <el-input
            v-model="form.returnVolume"
            type="number"
            placeholder="请填写"
          />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="subTt">确 定</el-button>
        <el-button @click="ttOpen = false">取 消</el-button>
      </div>
    </el-dialog>

    <!-- 标记退砼 -->
    <el-dialog
      title="可降级范围"
      :visible="jjList.length > 0"
      @update:visible="jjList = []"
      width="500px"
      append-to-body
    >
      <el-table border :data="jjList">
        <el-table-column label="名称" align="center" prop="name" />
      </el-table>
    </el-dialog>

    <!-- 转售 -->
    <!-- <el-dialog
      title="退剩砼转售"
      :visible.sync="zsOpen"
      width="1000px"
      append-to-body
    >
      <el-form
        label-position="left"
        ref="zs-form"
        :model="zsForm"
        :rules="rules"
        label-width="80px"
      >
        <div>
          <div>降级/同级转售，可降级标号包括：xxxx折行显示</div>
          <div>
            本次发砼含退剩砼xxxx方，主标号xxxx，附加标号xxxx，来自订单编号xxxx
          </div>
        </div>
        <el-card style="margin-top: 10px">
          <el-form-item
            :rules="[{ required: true, message: '请填写', trigger: 'blur' }]"
            label="转售至订单"
            label-width="100px"
            prop="orderId"
          >
            <div style="display: flex; gap: 20px">
              <el-input
                :disabled="orderInfo"
                v-model="zsForm.orderId"
                placeholder="请粘贴订单编号"
              />
              <el-button
                v-if="!orderInfo"
                @click="getOrders(zsForm.orderId)"
                type="primary"
                >显示该订单发砼信息</el-button
              >
              <el-button v-else @click="orderInfo = null" type="primary"
                >重选</el-button
              >
            </div>
          </el-form-item>
        </el-card>
        <el-card style="margin-top: 10px">
          <el-form-item
            :rules="[{ required: true, message: '请填写', trigger: 'blur' }]"
            label="退剩砼车"
            label-width="100px"
            prop="orderId"
          >
            <div
              style="display: flex; gap: 20px; justify-content: space-between"
            >
              <Car
                :carInfo="{
                  carNumber: '002',
                  status: 'bluecar',
                }"
              ></Car>
              <el-button style="height: 36px;" type="primary" @click="subZs">更换</el-button>
            </div>
          </el-form-item>
        </el-card>
        <el-card style="margin-top: 10px">
          <el-row>
            <el-col :span="8">
              <el-form-item
                :rules="[
                  { required: true, message: '请填写', trigger: 'blur' },
                ]"
                label="泵车"
                label-width="100px"
                prop="orderId"
              >
                <div style="display: flex; gap: 20px">
                  <div>1111</div>
                  <el-button type="primary" @click="subZs">更换</el-button>
                </div>
              </el-form-item>
            </el-col>
            <el-col :offset="3" :span="8">
              <el-form-item
                :rules="[
                  { required: true, message: '请填写', trigger: 'blur' },
                ]"
                label="泵送员"
                label-width="100px"
                prop="orderId"
              >
                <div style="display: flex; gap: 20px">
                  <div>1111</div>
                  <el-button type="primary" @click="subZs">更换</el-button>
                </div>
              </el-form-item>
            </el-col>
          </el-row>
        </el-card>
        <el-card style="margin-top: 10px">
          <el-row>
            <el-col :span="8">
              <el-form-item
                :rules="[
                  { required: true, message: '请填写', trigger: 'blur' },
                ]"
                label="泵浆方量"
                prop="pumpSlurryVolume"
              >
                <el-input
                  v-model="zsForm.pumpSlurryVolume"
                  placeholder="请填写"
                />
              </el-form-item>
              <el-form-item
                :rules="[
                  { required: true, message: '请填写', trigger: 'blur' },
                ]"
                label="生产方量"
                prop="productVolume"
              >
                <el-input v-model="zsForm.productVolume" placeholder="请填写" />
              </el-form-item>
              <el-form-item
                :rules="[
                  { required: true, message: '请填写', trigger: 'blur' },
                ]"
                label="运输方量"
                prop="transVolume"
              >
                <el-input v-model="zsForm.transVolume" placeholder="请填写" />
              </el-form-item>
            </el-col>
            <el-col :offset="3" :span="8">
              <el-form-item
                :rules="[
                  { required: true, message: '请填写', trigger: 'blur' },
                ]"
                label="生产机组"
                prop="productUnits"
              >
                <el-select v-model="queryParams.type" placeholder="请选择">
                  <el-option
                    v-for="item in sysUnitList"
                    :key="item.id"
                    :label="item.dictLabel"
                    :value="item.dictValue"
                  ></el-option>
                </el-select>
              </el-form-item>
            </el-col>
          </el-row>
        </el-card>
        <el-card style="margin-top: 10px" v-if="orderInfo">
          <el-row>
            <el-col :span="11">
              <div>累计发砼</div>
              <div>已生产方量：{{ orderInfo.squareAmount }}</div>
              <div>已运输方量：{{ orderInfo.squareAmount }}</div>
              <div>已发车次：{{ orderInfo.squareAmount }}</div>
            </el-col>
            <el-col :offset="2" :span="11">
              <div>累计泵浆</div>
              <div>已泵浆量：{{ orderInfo.squareAmount }}</div>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="11">
              <div>订单信息</div>
              <div>计划方量：{{ orderInfo.squareAmount }}</div>
              <div>计划开工时间：{{ orderInfo.startTime }}</div>
              <div>部位名称：{{ orderInfo.positionName }}</div>
              <div>主产品标号：{{ orderInfo.primaryDesignatorId }}</div>
              <div>附加产品标号：{{ orderInfo.additionalTitleIds }}</div>
              <div>泵送类型：{{ orderInfo.pumpingId }}</div>
              <div>订单编号：{{ orderInfo.orderNumber }}</div>
            </el-col>
            <el-col :offset="2" :span="11">
              <div>工程信息</div>
              <div>工程名称：{{ orderInfo.engineeringId }}</div>
              <div>施工地点：{{ orderInfo.engineeringId }}</div>
              <div>施工单位：{{ orderInfo.engineeringId }}</div>
              <div>工程ID：{{ orderInfo.engineeringId }}</div>
              <div>现场联系人：{{ orderInfo.engineeringId }}</div>
              <div>运距：{{ orderInfo.engineeringId }}</div>
            </el-col>
          </el-row>
        </el-card>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="subZs">签 发</el-button>
        <el-button @click="zsOpen = false">取 消</el-button>
      </div>
    </el-dialog> -->

    <!-- 转售 -->
    <ZsDialog
      :open.sync="zsOpen"
      ref="concreteDialog"
      :sysUnitList="sysUnitList"
    ></ZsDialog>

    <SelectSalesmanDialog
      :dialogVisible="selectNameVisible"
      @onClose="selectNameVisible = false"
      :defauleUser="defauleUser"
      @onSubmit="selectName"
    ></SelectSalesmanDialog>
    <SelectNamemanDialog
      :multiple="false"
      :dialogVisible="selectName1Visible"
      @onClose="selectName1Visible = false"
      @onSubmit="selectName"
    ></SelectNamemanDialog>

    <SelectRoleDialog
      :dialogVisible="selectRoleVisible"
      @onClose="selectRoleVisible = false"
      @onSubmit="selectRole"
    >
    </SelectRoleDialog>
    <SelectMainDialog
      :dialogVisible="selectMainVisible"
      @onClose="selectMainVisible = false"
      :defaultMains="defaultMains"
      @onSubmit="selectMains"
    ></SelectMainDialog>
  </div>
</template>

<script>
import {
  getTeam,
  delTeam,
  addTeam,
  updateTeam,
} from "@/api/service/production/team";
import { getOrders } from "@/api/service/orderCenter/custom";
import {
  returnList,
  addData,
  putData,
  addResale,
  getDesignByIds,
} from "@/api/service/production/managementAndResaleOfLeftoverConcrete";
import SelectSalesmanDialog from "@/components/SelectDialog/SelectSalesmanDialog";
import SelectRoleDialog from "@/components/SelectDialog/SelectRoleDialog";
import SelectMainDialog from "@/components/SelectDialog/SelectMainDialog";
import { getDicts } from "@/api/system/dict/data";
import Car from "@/components/Car";
import QuickFilterDate from "@/components/QuickFilterDate"
import ZsDialog from "./components/ZsDialog";
export default {
  components: {
    Car,
    ZsDialog,
    QuickFilterDate,
    SelectMainDialog,
    SelectSalesmanDialog,
    SelectRoleDialog,
    SelectNamemanDialog: SelectSalesmanDialog,
  },
  name: "Team",
  data() {
    return {
      zsOpen: false,
      selectMainVisible: false,
      selectName1Visible: false,
      empIdIndex: -1,
      roleIndex: -1,
      selectRoleVisible: false,
      selectNameVisible: false,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 班组表格数据
      teamList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        startCreateTime: null,
        endCreateTime: null,
        returnType: null,
        handleResult: null,
        carNumber: null,
        carOwner: null,
      },
      // 表单参数
      form: {},
      zsForm: {},
      // 表单校验
      rules: {},

      orderInfo: null,

      stOpen: false,
      ttOpen: false,
      clOpen: false,
      jjList: [],

      sysUnitList: [],
    };
  },
  async created() {
    this.getList();
    const res = await getDicts("sys_unit");
    this.sysUnitList = res.data;
  },
  computed: {
    queryDateArr: {
      get() {
        if (this.queryParams?.startCreateTime) {
          return [
            this.queryParams?.startCreateTime,
            this.queryParams?.endCreateTime,
          ];
        }
        return [];
      },
      set(value) {
        this.queryParams.startCreateTime = value[0];
        this.queryParams.endCreateTime = value[1];
      },
    },
    defaultMains() {
      if (this.form.demoteDesignIds && this.form.demoteDesignNames) {
        const ids = this.form.demoteDesignIds.split(",");
        const names = this.form.demoteDesignNames.split(",");
        return ids.map((id, index) => ({
          id: id,
          name: names[index],
        }));
      }
      return [];
    },
    defauleUser() {
      if (this.form.teamRoleList && this.empIdIndex != -1) {
        return this.form.teamRoleList[this.empIdIndex].empIdLIst.map(
          (item) => ({
            userId: item.id,
            nickName: item.name,
          })
        );
      }
      return [];
    },
  },
  methods: {
    async handleJjfw(row) {
      if (!row.primaryDesignatorId) return 
      const res = await getDesignByIds(row.primaryDesignatorId);
      this.jjList = res.rows;
    },
    async getOrders(id) {
      if (!id) {
        this.$message({
          message: "请先输入订单号",
          type: "warning",
        });
        return;
      }
      const res = await getOrders(id);
      this.orderInfo = res.data;
    },
    handleTt(row) {
      this.reset();
      this.form = row;
      this.ttOpen = true;
    },
    selectMains(arr) {
      this.form.demoteDesignIds = arr.map((item) => item.id).join(",");
      this.form.demoteDesignNames = arr.map((item) => item.name).join(",");
    },
    async subZs() {
      await this.$refs["zs-form"].validate();
      addResale(this.zsForm).then((response) => {
        this.$modal.msgSuccess("操作成功");
        this.zsOpen = false;
        this.getList();
      });
    },
    async subTt() {
      await this.$refs["tt-form"].validate();
      addData({
        concreteId: this.form.concreteId,
        carNumber: this.form.carNumber,
        returnType: 0,
        returnVolume: this.form.returnVolume,
      }).then((response) => {
        this.$modal.msgSuccess("标记成功");
        this.ttOpen = false;
        this.getList();
      });
    },
    handleZf(row) {
      this.$confirm("确定要作废吗?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(async () => {
          await putData({
            concreteId: row.concreteId,
            handleResult: "5",
          });
          this.$message({
            type: "success",
            message: "操作成功!",
          });
          this.getList();
        })
        .catch(() => {
          // this.$message({
          //     type: 'info',
          //     message: '已取消删除'
          // });
        });
    },
    handleZs(row) {
      this.zsForm = {
        carList: [],
        userList: [],
        demoteDesignIds: row.demoteDesignIds,
        concreteNo: null,
        pumpSlurryVolume: null,
        pumpingVolume: null,
        productVolume: null,
        transVolume: null,
        pumpcarNumber: null,
        pumpCarDriver: null,
        productUnits: null,
        productUnitNsmes: null,
        orderId: null,
        engineeringId: null,
        concreteStatus: null,
        settledStatus: null,
        receiptCode: null,
        receiptStatus: null,
        receiptTime: null,
        transDistance: null,
      };
      this.zsOpen = true;
    },
    handleCl(row) {
      this.reset();
      this.form = row;
      this.clOpen = true;
    },
    async subCl() {
      await this.$refs["cl-form"].validate();
      putData({
        concreteId: this.form.concreteId,
        handleResult: this.form.handleResult,
        demoteDesignIds: this.form.demoteDesignIds,
      }).then((response) => {
        this.$modal.msgSuccess("标记成功");
        this.clOpen = false;
        this.getList();
      });
    },
    handleSt(row) {
      this.reset();
      this.form = row;
      this.stOpen = true;
    },
    async subSt() {
      await this.$refs["st-form"].validate();
      addData({
        concreteId: this.form.concreteId,
        carNumber: this.form.carNumber,
        returnType: 1,
        returnVolume: this.form.returnVolume,
      }).then((response) => {
        this.$modal.msgSuccess("标记成功");
        this.stOpen = false;
        this.getList();
      });
    },
    addEmpIdLIst(scope) {
      this.empIdIndex = scope.$index;
      this.selectNameVisible = true;
    },
    selectRole(row) {
      this.form.teamRoleList[this.roleIndex].roleId = row.roleId;
      this.form.teamRoleList[this.roleIndex].roleName = row.roleName;
    },
    deleteEmp(mainIndex, subIndex) {
      this.form.teamRoleList[mainIndex].empIdLIst.splice(subIndex, 1);
    },
    removeRole(scope) {
      this.form.teamRoleList.splice(scope.$index, 1);
    },
    selectRoleName(scope) {
      this.roleIndex = scope.$index;
      this.selectRoleVisible = true;
    },
    addRow() {
      this.form.teamRoleList.push({
        roleId: null,
        roleName: null,
        empIdLIst: [],
      });
    },
    selectName(arr) {
      if (this.empIdIndex == -1) {
        this.form.teamLeaderId = arr.userId;
        this.form.teamLeaderName = arr.nickName;
      } else {
        this.form.teamRoleList[this.empIdIndex].empIdLIst = arr.map((item) => ({
          id: item.userId,
          name: item.nickName,
        }));
      }
      this.empIdIndex = -1;
    },
    /** 查询班组列表 */
    getList() {
      this.loading = true;
      returnList(this.queryParams).then((response) => {
        this.teamList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        teamId: null,
        teamName: null,
        teamType: null,
        teamLeaderId: null,
        demoteDesignIds: null,
        demoteDesignNames: null,
        teamRoleList: [],
        status: "1",
        delFlag: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        remark: null,
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.queryParams.startCreateTime = null;
      this.queryParams.endCreateTime = null;
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.teamId);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加班组";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const teamId = row.teamId || this.ids;
      getTeam(teamId).then((response) => {
        response.data.teamRoleList.forEach((item) => {
          item.empIdLIst = item.teamEmpList.map((t) => ({
            id: t.empId,
            name: t.empName,
          }));
        });

        this.form = response.data;
        this.open = true;
        this.title = "修改班组";
      });
    },
    /** 提交按钮 */
    submitForm() {
      const subForm = JSON.parse(JSON.stringify(this.form));
      subForm.teamRoleList.forEach((item) => {
        item.empIdLIst = item.empIdLIst.map((e) => e.id);
      });

      this.$refs["form"].validate((valid) => {
        if (valid) {
          if (this.form.teamId != null) {
            updateTeam(subForm).then((response) => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addTeam(subForm).then((response) => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const teamIds = row.teamId || this.ids;
      this.$modal
        .confirm('是否确认删除班组编号为"' + teamIds + '"的数据项？')
        .then(function () {
          return delTeam(teamIds);
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        })
        .catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download(
        "system/team/export",
        {
          ...this.queryParams,
        },
        `team_${new Date().getTime()}.xlsx`
      );
    },
  },
};
</script>


<style lang="scss" scoped>
::v-deep .el-tabs__content {
  max-height: 500px;
  overflow: auto;
}
::v-deep .el-dialog__body {
  max-height: 700px;
  overflow: auto;
}
</style>
